package com.cjl.multi_thread.aqs;

import java.util.concurrent.atomic.AtomicReference;

public class UseAtomicRef {

    static AtomicReference<UserInfo> userInfoAtomicReference = new AtomicReference<>();

    public static void main(String[] args) {
        UserInfo userInfo = new UserInfo("M",16);
        userInfoAtomicReference.set(userInfo);
        UserInfo updateUserInfo = new UserInfo("G",20);
        userInfoAtomicReference.compareAndSet(userInfo,updateUserInfo);

        System.out.println("UseAtomicRef.main "+userInfoAtomicReference.get().getName());
        System.out.println("UseAtomicRef.main "+userInfoAtomicReference.get().getAge());

        System.out.println("UseAtomicRef.main "+userInfo.getName());
        System.out.println("UseAtomicRef.main "+userInfo.getAge());

        //不是更新userInf对象本身   指向某内存地址上的值


    }

    static class UserInfo{
        private String name;
        private int age;

        public UserInfo(String name, int age) {
            this.name = name;
            this.age = age;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public int getAge() {
            return age;
        }

        public void setAge(int age) {
            this.age = age;
        }
    }

}
